<template>
    <div>
        <h1>医生新增</h1>
        <table class="table">
            <tr>
                <td>姓名</td>
                <td><input type="text" v-model="data.dname"></td>
            </tr>
            <tr>
                <td>头像</td>
                <td>
                    <input type="file" @change="sc">
                    <img :src="'https://localhost:7173/'+data.dimage" style="width: 60px;height: 60px;">
                </td>
            </tr>
            <tr>
                <td>科室</td>
                <td><select v-model="data.rid">
                    <option value="0">请选择</option>
                    <option v-for="x in xl" :value="x.rid">{{x.rname}}</option>
                </select></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="新增" @click="add"></td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import moment from 'moment'
const router=useRouter();
const route=useRoute();
const data=ref({
    "did": 0,
  "dname": "",
  "dimage": "",
  "rid": 0,
  "dtime": "2025-05-19T03:41:00.131Z"
})
const add=()=>{
    if(data.value.dname==""){
        alert("姓名不能为空")
        return
    }
    axios.post("/api/Doute/AddDoute",data.value).then(res=>{
        if(res.data>0){
            alert("新增成功")
            router.push({path:"/dshow"})
        }else{
            alert("新增失败")
            return
        }
    })
}
onMounted(() => {
  xlk()  
})
const xl=ref({})
const xlk=()=>{
    axios.get("/api/RoomKs/GetRoomKsBy").then(res=>{
        xl.value=res.data
    })
}
const sc=(e:any)=>{
    var f=e.target.files[0]
    var fd=new FormData()
    fd.append("file",f);
    if(f.size>2*1024*1024){
        alert("文件大小不能超过2MB")
        return
    }
    axios.post("/api/Doute/DouteImage",fd).then(res=>{
        data.value.dimage=res.data
    })
}
</script>

<style scoped>

</style>